<!--
 * @Description: 
 * @Author: 胡涛
 * @Date: 2023-06-08 14:40:02
 * @LastEditors: 胡涛
 * @LastEditTime: 2024-01-21 19:47:43
-->
<template>
  <a-menu class="menu">
    <div class="user-header" @click="onChangeAccount">
      <div class="avatar">
        <a-avatar
          style="background-color: #fff"
          :size="48"
          src="./images/avatar.svg"
        >
        </a-avatar>
      </div>
      <div class="info">
        <div class="name">{{ currentUser.name }}</div>
        <div class="email">{{ currentUser.phoneNumber }}</div>
      </div>
    </div>
    <a-menu-item @click="onChangeAccount">我的资料</a-menu-item>
    <a-menu-item @click="onChangePassword">修改密码</a-menu-item>
    <a-menu-item @click="onLogout">退出登录</a-menu-item>
  </a-menu>
  <ChangePasswordForm
    v-model:visible="changePasswordVisible"
    v-if="changePasswordVisible"
  />
  <ChangeAccountForm
    v-model:visible="changeAccountVisible"
    v-if="changeAccountVisible"
  />
</template>

<script lang="ts" setup>
import { useAppStore, useDataStore } from "@/store";
import { storeToRefs } from "pinia";
import { useRouter } from "vue-router";
import ChangePasswordForm from "@/views/account/ChagePassword.vue";
import ChangeAccountForm from "@/views/account/Edit.vue";
import { nextTick, ref } from "vue";
const appStore = useAppStore();
const dataStore = useDataStore();
const { currentUser } = storeToRefs(appStore);
const router = useRouter();
const changePasswordVisible = ref(false);
const changeAccountVisible = ref(false);
const onSysteSettings = () => {
  router.push("/system/setting");
};

const onChangeAccount = () => {
  changeAccountVisible.value = true;
};

const onChangePassword = () => {
  changePasswordVisible.value = true;
};

const onLogout = () => {
  appStore.logout();
  dataStore.setAllDictionaryItems([]);
  dataStore.setAllRoleItems([]);
  dataStore.setAllUserItems([]);
  dataStore.setAllOrganizationItems([]);
  dataStore.setAllEnterpriseItems([]);
  router.push("/login");
  nextTick(() => {
    location.reload();
  });
};
</script>

<style lang="less" scoped>
.menu {
  margin-top: 5px;
  background: #fff;
}
.user-header {
  margin: -4px -4px 5px;
  width: 200px;
  background: linear-gradient(
    115deg,
    #e3f0ff 1%,
    #e3f0ff 1%,
    #f0fdff 100%,
    #f0fdff 100%
  );
  padding: 24px 0 24px 18px;
  display: flex;

  .avatar {
    margin-right: 10px;
  }
  .info {
    flex: 1;

    .name {
      cursor: text;
      font-size: 16px;
      font-weight: 400;
      color: #1f2126;
      line-height: 24px;
      padding-right: 18px;
      text-overflow: ellipsis;
      overflow: hidden;
      word-break: break-all;
      -webkit-line-clamp: 1;
      -webkit-box-orient: vertical;
      position: relative;
    }
    .email {
      margin-top: 2px;
      cursor: text;
      color: #1f212680;
      font-size: 12px;
      line-height: 20px;
      padding-right: 18px;
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
      word-break: break-all;
    }
  }
}

.divider {
  margin: 5px 0;
}
</style>
